<blockquote>
    <p>定义Handler</p>
    <footer>
        自定义链必须实现Handler接口
    </footer>
</blockquote>
<blockquote>
    <p>示例 <code>AuthHandler.java</code></p>
</blockquote>
<pre class="code brush:java">
package cn.jants.demos.handler;

import cn.jants.core.ext.Handler;
import cn.jants.restful.render.Json;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author MrShun
 * @version 1.0
 */
public class AuthHandler implements Handler {

    /**
     * 执行链
     *
     * @param target
     * @param request
     * @param response
     * @return true/进入到下个链, false/直接在当前链返回
     */
    @Override
    public boolean preHandler(String target, HttpServletRequest request, HttpServletResponse response) throws Exception {
        if (target.startsWith("/admin")) {
            //TODO 执行逻辑 然后在此页面输出结果, 或跳转页面
            Json.writeJson("被拦截了....", response);
            return false;
        }
        return true;
    }
}

</pre>
<blockquote>
    <p>示例 配置Handler</p>
    <footer style="color:red;">必须继承AppConfiguration对象覆盖父类方法</footer>
</blockquote>
<pre class="code brush:java">
package cn.jants.demos;


import cn.jants.common.annotation.action.Controller;
import cn.jants.common.annotation.action.GET;
import cn.jants.common.annotation.boot.PropertyConfiguration;
import cn.jants.common.annotation.plugin.EnableActiveMQPlugin;
import cn.jants.common.annotation.service.Aop;
import cn.jants.common.annotation.service.Application;
import cn.jants.common.annotation.service.Autowired;
import cn.jants.common.bean.JsonMap;
import cn.jants.core.context.AppConfiguration;
import cn.jants.core.handler.LimitRefreshHandler;
import cn.jants.core.handler.PathHandler;
import cn.jants.core.module.HandlerManager;
import cn.jants.core.module.InterceptorManager;
import cn.jants.core.startup.JTomcat;
import cn.jants.demos.Interceptor.TestInterceptor;
import cn.jants.demos.handler.AuthHandler;
import cn.jants.plugin.jms.ActiveMqTpl;


/**
 * Tomcat 方式启动
 *
 * @author MrShun
 * @version 1.0
 * @Date 2017/12/20
 */
@Application
@PropertyConfiguration
@Controller
public class DemosApplication extends AppConfiguration{


    @GET("/aop/test")
    @Aop(TestInterceptor.class)
    public void test(){
        System.out.println("测试Aop Interceptor拦截器...");
    }

    @Override
    public void configHandler(HandlerManager handlers) {
        //添加自定义链
        handlers.add(new AuthHandler());
        /**
         * 添加限制频繁刷新接口，框架自带
         * 参数一：指定刷清空存时间，当前是12小时清空一次
         * 参数二：指定多长时间算是频繁，当前是3秒
         * 参数三：刷新多少算是频繁，当前是10次
         * 参数四：指定匹配URL
         */
        handlers.add(new LimitRefreshHandler(1000*60*12, 3000, 10, "/api"));
        //设置量路径,渲染页面可以直接${ctx}取值
        JsonMap pathMap = JsonMap.newJsonMap();
        pathMap.put("ctx", "");
        pathMap.put("STATIC_CSS", "/static/css");
        pathMap.put("STATIC_JS", "/static/js");
        pathMap.put("STATIC_IMG", "/static/images");
        handlers.add(new PathHandler(pathMap));
    }

    public static void main(String[] args) {
        JTomcat.run(DemosApplication.class, 80, "/demo");
    }
}
</pre>
<script type="text/javascript">
    $(function () {
        SyntaxHighlighter.highlight();
        $(".toolbar").remove();
    });
</script>